package com.pengbei.enshrine.common.dialog.callback;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.pengbei.enshrine.R;

import java.util.ArrayList;
import java.util.List;

public class AppUpdateAdapter extends RecyclerView.Adapter {

    private Context context;
    private LayoutInflater mInflater;
    private List<String> dlist;

    public AppUpdateAdapter(Context context, List<String> dlist) {
        this.context = context;
        mInflater = LayoutInflater.from(context);
        setList(dlist);
    }

    public void setList(List<String> dlist) {
        if (dlist != null) {
            this.dlist = dlist;
        } else {
            this.dlist = new ArrayList<String>();
        }
    }

    public void change(List<String> dlist) {
        setList(dlist);
        this.notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_appupdate, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.tv_updatemsg.setText(dlist.get(position).toString().trim());
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv_updatemsg;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_updatemsg = (TextView) itemView.findViewById(R.id.tv_updatemsg);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return dlist.size();
    }


}